<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<form id="form" style="justify-items:center">
    <div style= margin-left:100px>
        <Text>创建流程</Text></br>
        <!--<input id="formName">formName</input></br>-->
        <!--<input id="title_">title_</input></br>-->
        <input onchange="setValue" id="flowId">flowId</input></br>
        <input onchange="setValue" id="title">title</input></br>
        <button style="margin-top:20px" type="button" id="det">创建</button>
    </div>
</form>
</body>

<script type="text/javascript" src="./swagger/lib/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
    var title = "";
    var flowId = "";
    var asToken = "";
    var trackId = "";
    getToken();
    function getToken(){
        var formData = {
            "loginName": "admin",
            "password": "1234",
        }
        $.ajax({
            url: "http://127.0.0.1:9999/ocndy/api/demo/sendHzLogin",
            type:"post",
            dataType:"text",
            contentType:'application/json;charset=utf-8',
            data:JSON.stringify(formData),
            processData : false,//是否序列化
            success: function (result) {
                asToken = result.data.accessToken;
                // alert(JSON.stringify(result))

            },
            error: function (result) {
                alert("err"+JSON.stringify(result))
            }
        });
    }
    function setValue (k){
        flowId = $("#flowId").val();
        title = $("#title").val();
    }

    $("#det").click(function () {
        if(flowId || title == ""){
            alert("flowId 或 title 不能为空")
            return;
        }
        var formData = {
            "flowId": flowId,
            "title": title,
            "accessToken": asToken,
        }
        $.ajax({
            url: "http://10.10.29.222:1204/horizon-workflow-web/horizon/workflow/rest/flow/support/open.wf",

            dataType: "json",
            type: "post",
            data: formData,

            success: function (result) {
                trackId = result.flowNode.trackId;
                // alert(result.msg);
                window.location.href='http://localhost:9999/ocndy/fillForm.html?'+trackId;
            },
            error: function (data) {
                alert("请求出错");
            }
        });
    });
</script>
</html>